package com.hp.controller;

import com.hp.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class GroupController {

    @Autowired
    private GroupService groupService;

    // 创建群聊
    @PostMapping("addGroup")
    public HashMap<String, Object> addGroup(int ownerId, String groupName) {
        return groupService.addGroup(ownerId, groupName);
    }

    // 解散群聊
    @PostMapping("delGroup")
    public HashMap<String, Object> delGroup(int groupId) {
        return groupService.delGroup(groupId);
    }

    // 修改群名
    @PostMapping("updateGroupName")
    public HashMap<String, Object> updateGroupName(int groupId, String groupName) {
        return groupService.updateGroupName(groupId, groupName);
    }

    // 添加成员
    @PostMapping("addMember")
    public HashMap<String, Object> addMember(int groupId, int memberId, String memberName){
        return groupService.addMember(groupId, memberId, memberName);
    }

    // 删除成员
    @PostMapping("delMember")
    public HashMap<String, Object> delMember(int groupId, int memberId) {
        return groupService.delMember(groupId, memberId);
    }

    // 查找所有群成员
    @PostMapping("selectAllMember")
    public HashMap<String, Object> selectAllMember(int groupId) {
        return groupService.selectAllMember(groupId);
    }

    // 修改成员昵称
    @PostMapping("updateMemberName")
    public HashMap<String, Object> updateMemberName(int groupId, int memberId, String memberName) {
        return groupService.updateMemberName(groupId, memberId, memberName);
    }

    // 查找用户加入的群聊
    @PostMapping("selectAllGroup")
    public HashMap<String, Object> selectAllGroup(int userId) {
        return groupService.selectAllGroup(userId);
    }

    // 修改群头像
    @PostMapping("updateGroupPhoto")
    public HashMap<String, Object> updateGroupPhoto(int groupId, String groupPhoto) {
        return groupService.updateGroupPhoto(groupId, groupPhoto);
    }

    // 通过群号或群名称查找群
    @PostMapping("selectGroupByIdOrName")
    public HashMap<String, Object> selectGroupByIdOrName(String content) {
        return groupService.selectGroupByIdOrName(content);
    }

    // 查询群验证消息
    @PostMapping("selectGroupVerifications")
    public HashMap<String, Object> selectGroupVerifications(int userId, int groupId, int fromId) {
        return groupService.selectGroupVerifications(userId, groupId, fromId);
    }

    // 更新验证消息（申请进群）
    @PostMapping("updateVerificationOfApply")
    public HashMap<String, Object> updateVerificationOfApply(int fromId, int groupId, int verificationStatus) {
        return groupService.updateVerificationOfApply(fromId, groupId, verificationStatus);
    }

    // 更新验证消息（管理员邀请进群）
    @PostMapping("updateVerificationOfInvite")
    public HashMap<String, Object> updateVerificationOfInvite(int fromId, int toId, int groupId, int verificationStatus) {
        return groupService.updateVerificationOfInvite(fromId, toId, groupId, verificationStatus);
    }

}
